package com.qin.entity.subcomponents;

import com.qin.entity.ExecuteBean;
import com.qin.entity.ExecuteLog;
import com.qin.service.ExecuteService;
import com.qin.service.impl.ExecuteServiceImpl;

/*
 * 【子组件】变量校验
 */
public class CheckParaSubComponent {

    //临时变量名
    private String check_paraname;
    //预期值
    private String check_expect_value;

    private ExecuteService executeService = new ExecuteServiceImpl();

    public CheckParaSubComponent(String check_paraname, String check_expect_value) {
        this.check_paraname = check_paraname;
        this.check_expect_value = check_expect_value;
    }

    public void execute(ExecuteBean executeBean){

        //设置ExecuteLog对象的各属性
        ExecuteLog executeLog = new ExecuteLog(executeBean.getExecute_id(), executeBean.getFunction_id(),
                executeBean.getTestcase_id(), executeBean.getComponent_id(), executeBean.getSubcomponent_id(), "");

        String check_real_value = executeBean.getParaMap().get(check_paraname);

        //插入日志
        executeService.insertExecuteLog(executeLog, ">>>>>变量校验：变量" + check_paraname + "实际值=" + check_real_value);
        executeService.insertExecuteLog(executeLog, ">>>>>变量校验：变量" + check_paraname + "预期值=" + check_expect_value);

        if(check_expect_value.equals(check_real_value)){
            //插入日志
            executeService.insertExecuteLog(executeLog, ">>>>>变量校验：校验通过");
        }
        else{
            //插入日志
            executeService.insertExecuteLog(executeLog, ">>>>>变量校验：校验不通过");
            throw new NullPointerException();
        }
    }
}
